<?php
require_once ("C_krn_audit.php");
//require_once ("C_krn_exception.php");

// Funciones utiles
class c_krn_net {
	
	// Evitamos el clonaje del objeto. Patrón Singleton
	private function __clone() {
	}
	private function __wakeup() {
	}
	private static $_instance;
	public static function getInstance() {
		if (! (self::$_instance instanceof self)) {
			self::$_instance = new self ();
		}
		
		return self::$_instance;
	}
	function is_valid_ip($ip, $include_priv_res = true) {
		return $include_priv_res ? filter_var ( $ip, FILTER_VALIDATE_IP ) !== false : filter_var ( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false;
	}
	
	function getIP_External () {
	  return file_get_contents('http://phihag.de/ip/');
	}
	function getIP() {
		global $IDIOMA, $language;
		global $cAUDIT;
		try {
			if (getenv ( "HTTP_CLIENT_IP" ) && strcasecmp ( getenv ( "HTTP_CLIENT_IP" ), "0.0.0.0" )) {
				$ip = getenv ( "HTTP_CLIENT_IP" );
			} elseif (getenv ( "HTTP_X_FORWARDED_FOR" ) && strcasecmp ( getenv ( "HTTP_X_FORWARDED_FOR" ), "0.0.0.0" )) {
				$ip = getenv ( "HTTP_X_FORWARDED_FOR" );
			} elseif (getenv ( "REMOTE_ADDR" ) && strcasecmp ( getenv ( "REMOTE_ADDR" ), "0.0.0.0" )) {
				$ip = getenv ( "REMOTE_ADDR" );
			} elseif (isset ( $_SERVER ['REMOTE_ADDR'] ) && $_SERVER ['REMOTE_ADDR'] && strcasecmp ( $_SERVER ['REMOTE_ADDR'], "0.0.0.0" )) {
				$ip = $_SERVER ['REMOTE_ADDR'];
			} else {
				$this->AddAudit ( AUDIT_APP, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, $language [$IDIOMA] [6] );
			}
			return $ip;
		} catch ( Exception $e ) {
			$cAUDIT->AddAudit ( AUDIT_EXTEND, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, $e->getMessage () );
		}
	}
	function check_email_address($pEMAIL) {
		return filter_var ( $pEMAIL, FILTER_VALIDATE_EMAIL );
	}
	
	/*
	 * public function Validar_Email ( $pEMAIL ) { if (preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',$pEMAIL)) return true; else return false; }
	 */
	function __construct() {
		global $cAUDIT;
		$cAUDIT->AddAudit ( AUDIT_EXTEND, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, "::constructor (" . __CLASS__ . ")" );
	}
}
;

// Instancia de la clase
try {
	// Instancia de la clase
	$cNET = c_krn_net::getInstance ();
} catch ( Exception $e ) {
	global $IDIOMA, $language;
	echo $language [$IDIOMA] [59] . $e->getMessage ();
}

?>
